/*
 * Copyright (c) 2020-2021 YangZeLin. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__

#include "menuconfig.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */

#define OS_SYS_CLOCK             (50000000)
#define SYS_CTRL_REG_BASE        IO_DEVICE_ADDR(0x12020000)
#define REG_SC_CTRL              0



/* memory config */
#define CACHE_ALIGNED_SIZE        (64)

// 256MB
#define DDR_MEM_ADDR            0x80000000 //imx6ull的硬件内存地址
#define DDR_MEM_SIZE            0x1C000000 //512M-64M的ramfs

#define SYS_MEM_SIZE_DEFAULT    0x2000000  //默认的，不知道有什么用

/* Peripheral register address base and size */
#define PERIPH_PMM_BASE         0x00a00000  //GIC的地址最低，选这个作为最低地址
#define PERIPH_PMM_SIZE         0x02300000  //选一个空间，让它包含你要用的外设，注意要1M对齐

/* ddr ramfs */
#define DDR_RAMFS_ADDR          (DDR_MEM_ADDR + DDR_MEM_SIZE)
#define DDR_RAMFS_SIZE          (0x4000000)  /* 64M ramfs */
#define DDR_RAMFS_REAL_SIZE     (0xa00000) 	/* ramfs real size */

/* kernel load address */
#define KERNEL_LOAD_ADDRESS     (0x80100000)

/* hwi */
/**
 * 查手册获取中断号列表
 * Maximum number of supported hardware devices that generate hardware interrupts.
 * The maximum number of hardware devices that generate hardware interrupts is 288.
 */
#define OS_HWI_MAX_NUM                  160
/**
 * Maximum interrupt number.
 */
#define OS_HWI_MAX                      ((OS_HWI_MAX_NUM) - 1)
/**
 * Minimum interrupt number.
 */
#define OS_HWI_MIN                       0
/**
 * Maximum usable interrupt number.
 */
#define OS_USER_HWI_MAX                 OS_HWI_MAX
/**
 * Minimum usable interrupt number.
 */
#define OS_USER_HWI_MIN                 OS_HWI_MIN

/*
    通用定时器中断号设置
    使用 Non-secure 的时钟中断
*/
#define NUM_HAL_INTERRUPT_CNTPSIRQ      29  /* Secure physical timer event. */
#define NUM_HAL_INTERRUPT_CNTPNSIRQ     30  /* Non-secure physical timer event. */
#define OS_TICK_INT_NUM                 NUM_HAL_INTERRUPT_CNTPSIRQ /* 使用 Non-secure physical timer 作为系统时钟中断 */

#define NUM_HAL_INTERRUPT_TIMER0        37
#define NUM_HAL_INTERRUPT_TIMER3        38
#define NUM_HAL_INTERRUPT_UART1         58

/* GIC base and size : 1M-align */
#define GIC_PHY_BASE            0x00A00000
//#define GIC_PHY_SIZE            0x100000

/* GIC */
#define GIC_BASE_ADDR             IO_DEVICE_ADDR(0x00a00000)
#define GICD_OFFSET               0x1000                          /* interrupt distributor offset */
#define GICC_OFFSET               0x2000                          /* CPU interface register offset */

/* use UART1 as debug uart */
#define UART1_REG_ADDR             0x02020000
#define UART1_REG_PBASE           (UART1_REG_ADDR + 0x0000)
#define UART1_REG_BASE            IO_DEVICE_ADDR(UART1_REG_PBASE)
#define TTY_DEVICE                "/dev/uartdev-1" //这里的数字与device/nxp/imx6ull_liteos/config/uart/uart_config.hcs中的num要对应
#define UART_REG_BASE             UART1_REG_BASE
#define NUM_HAL_INTERRUPT_UART    NUM_HAL_INTERRUPT_UART1

#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif
